DC Motor 28 FNG Click
DC Motor 28 FNG Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Stefan Filipovic
- Date : Jan 2025.
- Type : ADC type
Software Support
Example Description
This example demonstrates the use of the DC Motor 28 FNG Click board. It initializes the Click driver, calibrates the offset for accurate current measurements, and then controls the motor in different states while measuring and logging the output current in milliamps (mA).
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.DCMotor28FNG
Example Key Functions
- dcmotor28fng_cfg_setup Config Object Initialization function.
void dcmotor28fng_cfg_setup(dcmotor28fng_cfg_t *cfg)
DC Motor 28 FNG configuration object setup function.
DC Motor 28 FNG Click configuration object.
Definition dcmotor28fng.h:153
- dcmotor28fng_init Initialization function.
err_t dcmotor28fng_init(dcmotor28fng_t *ctx, dcmotor28fng_cfg_t *cfg)
DC Motor 28 FNG initialization function.
DC Motor 28 FNG Click context object.
Definition dcmotor28fng.h:135
- dcmotor28fng_drive_motor This function drives the motor in the selected PWM control mode state.
void dcmotor28fng_drive_motor(dcmotor28fng_t *ctx, uint8_t state)
DC Motor 28 FNG drive motor function.
- dcmotor28fng_calib_offset This function calibrates the zero current offset value.
err_t dcmotor28fng_calib_offset(dcmotor28fng_t *ctx)
DC Motor 28 FNG calib offset function.
- dcmotor28fng_get_out_current This function reads the current output measurement in mA.
err_t dcmotor28fng_get_out_current(dcmotor28fng_t *ctx, float *current)
DC Motor 28 FNG get out current function.
Application Init
Initializes the logger and the DC Motor 28 FNG Click driver and performs offset calibration for current measurements.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
{
log_error( &logger, " Offset calibration." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
@ DCMOTOR28FNG_ERROR
Definition dcmotor28fng.h:172
#define DCMOTOR28FNG_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition dcmotor28fng.h:120
void application_init(void)
Definition main.c:39
#define MIKROBUS_POSITION_DCMOTOR28FNG
Definition main.c:33
Application Task
Controls the motor in a sequence of states: FORWARD, BRAKE, REVERSE, and COAST. In each state, the output current is measured and logged, providing insights into the motor's performance and consumption.
{
float current = 0;
log_printf( &logger, " Motor state : FORWARD\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : BRAKE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : REVERSE\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
log_printf( &logger, " Motor state : COAST\r\n" );
Delay_ms ( 1000 );
Delay_ms ( 1000 );
{
log_printf( &logger, " Current : %.3f mA\r\n\n", current );
}
}
@ DCMOTOR28FNG_OK
Definition dcmotor28fng.h:171
#define DCMOTOR28FNG_MOTOR_COAST
DC Motor 28 FNG motor PWM control mode setting.
Definition dcmotor28fng.h:99
#define DCMOTOR28FNG_MOTOR_BRAKE
Definition dcmotor28fng.h:102
#define DCMOTOR28FNG_MOTOR_FORWARD
Definition dcmotor28fng.h:100
#define DCMOTOR28FNG_MOTOR_REVERSE
Definition dcmotor28fng.h:101
void application_task(void)
Definition main.c:75
Note
Ensure the PMODE switch is set to position 1 (HIGH), the motor is properly connected to the board OUT1 and OUT2 terminals, and the proper power supply is connected to the input terminal.
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.